package com.wnx.job.modules.jms.controller;


import com.wnx.job.common.api.Const;
import com.wnx.job.common.api.ResultData;
import com.wnx.job.common.mapstruct.ProfessionMapper;
import com.wnx.job.domain.CascadeNode;
import com.wnx.job.modules.jms.dto.ProfessionParam;
import com.wnx.job.modules.jms.model.JmsProfession;
import com.wnx.job.modules.jms.service.JmsProfessionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wangnaixing
 * @since 2021-12-17
 */
@Slf4j
@RestController
@RequestMapping("/jms/jmsProfession")
@Api(tags = "ProfessionController",description = "专业管理")
public class JmsProfessionController {
    @Resource
    private JmsProfessionService professionService;

    /**
     * 新增专业
     * @param professionParam
     * @return
     */
    @PostMapping("/save")
    @ApiOperation("新增专业")
    public ResultData<String> save(@Validated @RequestBody ProfessionParam professionParam){
        log.info("【=======系统正在增加专业中，该专业的信息为：============】");
        JmsProfession tbProfession = ProfessionMapper.INSTANCE.toPojo(professionParam);
        professionService.saveProfession(tbProfession);
        log.info("【==========系统新增专业成功！=============】");
        return ResultData.success(Const.ADD_PROFESSION_SUCCESS);
    }

    /**
     * 删除专业
     * @param id
     * @return
     */
    @GetMapping("/delete/{id}")
    @ApiOperation("删除专业")
    public ResultData<String> deleteProfession(@PathVariable(name = "id")Long id){
        log.info("【=========系统正在删除专业，删除专业ID为：{}=======】",id);
        professionService.deleteProfession(id);
        log.info("【============系统删除专业成功！！===========】");
        return ResultData.success(Const.DELETE_PROFESSION_SUCCESS);
    }


    /**
     * 修改专业名称
     * @param professionParam
     * @return
     */
    @PostMapping("/update")
    @ApiOperation("修改专业")
    public ResultData<String> update(@RequestBody @Validated  ProfessionParam professionParam){
        log.info("【=======系统正在修改专业中，该专业的信息为：============】");
        JmsProfession tbProfession = ProfessionMapper.INSTANCE.toPojo(professionParam);
        professionService.updateProfession(tbProfession);
        log.info("【============系统修改专业成功！！===========】");
        return ResultData.success(Const.UPDATE_PROFESSION_SUCCESS);
    }

    /**
     * 根据ID查询专业信息
     * @param id
     * @return
     */
    @GetMapping("/findById/{id}")
    @ApiOperation("根据ID查询专业信息")
    public ResultData<JmsProfession> findById(@PathVariable(name = "id")Long id){
        log.info("【=======系统正在根据ID查询专业中....============】");
        JmsProfession profession =  professionService.getById(id);
        log.info("【=======系统正在根据ID查询专业成功,该公司的信息为============】");
        return ResultData.success(Const.QUERY_PROFESSION_SUCCESS,profession);
    }


    /**
     * 获取级联专业树
     * @return
     */
    @GetMapping("/getProfessionTree")
    @ApiOperation("获取级联专业树")
    public ResultData<List<CascadeNode>> getProfessionTree(){
        log.info("【=====系统正在查询专业树中，请稍等....====】");
        List<CascadeNode> professionVoList =  professionService.getTree();
        log.info("【=====系统查询专业树成功！！====】");
        return ResultData.success(Const.QUERY_PROFESSION_TREE_SUCCESS,professionVoList);
    }


    /**
     * 查询全部专业
     * @return
     */
    @GetMapping("/findAll")
    @ApiOperation("查询全部专业")
    public ResultData<List<JmsProfession>> findAll(){
        log.info("【=====系统正在查询查询全部专业中，请稍等....====】");
        List<JmsProfession> professionList = professionService.list();
        log.info("【=====系统查询全部专业！！！====】");
        return ResultData.success(Const.QUERY_PROFESSION_SUCCESS,professionList);
    }






}

